<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <base href="#(basePath)"/>
    <title>交易管理 - 付款制单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="static/layui/css/layui.css" media="all">
</head>
<body>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 20px 0 0;">
    <input type="hidden" name="tradeOrder.youliAccountId">
    <div class="layui-form-item">
        <div class="layui-form-item">
            <label class="layui-form-label">暂存户</label>
            <div class="layui-input-block">
                <select name="tradeOrder.merchCode"  required  lay-verify="required">
                    <option value="">请选择出账暂存户</option>
                    #for(item:tempAccountList)
                    <option value="#(item.accountNo)">#(item.accountName)-#(item.accountNo)</option>
                    #end
                </select>
            </div>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">钱包用户</label>
        <div class="layui-input-block">
            <input type="text" name="accountName" placeholder="输入钱包用户开始模糊搜索" required  lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">钱包编号</label>
        <div class="layui-input-block">
            <input type="text" name="accountNo" required  lay-verify="required" readonly="readonly" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">金额</label>
        <div class="layui-input-block">
            <input type="text" id="chargeAmount" name="amount" required placeholder="金额" oninput="if(value.length>10)value=value.slice(0,10)" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">金额大写</label>
        <div class="layui-input-block">
            <input type="text" id="chargeAmountShowBig" readonly="readonly" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <input type="text" name="tradeOrder.goodsName" placeholder="描述" value="暂存户转账:" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认">
    </div>
</div>

<script src="static/layui/layui.js"></script>
<script src="static/menoy.js"></script>
<script type="text/javascript">
    function convertCurrency(money) {
        //汉字的数字
        var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
        //基本单位
        var cnIntRadice = new Array('', '拾', '佰', '仟');
        //对应整数部分扩展单位
        var cnIntUnits = new Array('', '万', '亿', '兆');
        //对应小数部分单位
        var cnDecUnits = new Array('角', '分', '毫', '厘');
        //整数金额时后面跟的字符
        var cnInteger = '整';
        //整型完以后的单位
        var cnIntLast = '元';
        //最大处理的数字
        var maxNum = 999999999999999.9999;
        //金额整数部分
        var integerNum;
        //金额小数部分
        var decimalNum;
        //输出的中文金额字符串
        var chineseStr = '';
        //分离金额后用的数组，预定义
        var parts;
        if (money == '') { return ''; }
        money = parseFloat(money);
        //超出最大处理数字
        if (money >= maxNum) { return ''; }
        if (money == 0) {
            chineseStr = cnNums[0] + cnIntLast + cnInteger;
            return chineseStr;
        }
        //转换为字符串
        money = money.toString();
        if (money.indexOf('.') == -1) {
            integerNum = money;
            decimalNum = '';
        } else {
            parts = money.split('.');
            integerNum = parts[0];
            decimalNum = parts[1].substr(0, 4);
        }
        //获取整型部分转换
        if (parseInt(integerNum, 10) > 0) {
            var zeroCount = 0;
            var IntLen = integerNum.length;
            for (var i = 0; i < IntLen; i++) {
                var n = integerNum.substr(i, 1);
                var p = IntLen - i - 1;
                var q = p / 4;
                var m = p % 4;
                if (n == '0') {
                    zeroCount++;
                } else {
                    if (zeroCount > 0) {
                        chineseStr += cnNums[0];
                    }
                    //归零
                    zeroCount = 0;
                    chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
                }
                if (m == 0 && zeroCount < 4) {
                    chineseStr += cnIntUnits[q];
                }
            }
            chineseStr += cnIntLast;
        }
        //小数部分
        if (decimalNum != '') {
            var decLen = decimalNum.length;
            for (var i = 0; i < decLen; i++) {
                var n = decimalNum.substr(i, 1);
                if (n != '0') {
                    chineseStr += cnNums[Number(n)] + cnDecUnits[i];
                }
            }
        }
        if (chineseStr == '') {
            chineseStr += cnNums[0] + cnIntLast + cnInteger;
        } else if (decimalNum == '') {
            chineseStr += cnInteger;
        }
        return chineseStr;
    }
</script>
<script>
    layui.config({
        base: '#(basePath)' //静态资源所在路径
    }).extend({
        index: 'lib/index',
    }).use(['index', 'form','autocomplete', 'upload'], function(){
        var $ = layui.$
            ,form = layui.form
            ,autocomplete = layui.autocomplete, upload = layui.upload;


        //自动填充账户信息
        autocomplete.render({
            elem: $('input[name="accountName"]')[0],
            url: layui.setter.base+"admin/merch/autocomplete",
            template_val: '{{d.code}}',
            template_txt: '{{d.code}} <span class=\'layui-badge layui-bg-gray\'>{{d.name}}</span>',
            onselect: function (resp) {
                    $('input[name="accountName"]').val(resp.name),
                    $('input[name="accountNo"]').val(resp.code)
            }
        }),

        $("#chargeAmount").bind("input",function(event){
            var money = this.value;
            var big = convertCurrency(money);
            $("#chargeAmountShowBig").val(big);
        });

        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function(data){
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                url: layui.setter.base+"admin/pay/payWalletTemp",
                type:"post",
                data: field,
                success: function(res){
                    if(res.code !== 0){
                        parent.layer.alert(res.msg, {icon: 2});
                    }else{
                        parent.layer.alert("执行成功，请往付款管理进行审核，复制付款单号: "+ res.msg, {icon: 1});
                        parent.layui.$("#LAY_app_body > div.layui-show iframe").get()[0].contentWindow.layui.table.reload('LAY-web-list'); //重载表格
                        parent.layer.close(index); //再执行关闭
                    }
                },
                error: function(xhr){parent.layer.msg("出错了" + xhr);}
            });
        });
    })


</script>

</body>
</html>
